﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Model;
using Lswweb.Domain;
using FredCK.FCKeditorV2;
using System.Configuration;

namespace Lswweb.Controls
{
    public class GuestBookAdd : SkinnedWebControl
    {
        private TextBox tbxTitle;
        private TextBox tbxEmail;
        private TextBox tbxPhone;
        private TextBox tbxBody;
        private TextBox tbxLinkMan;
        private TextBox tbxFax;
        private TextBox tbxMobile;
        private TextBox tbxAddress;
        private SexRadio rblSex;
        private GuestBookItemRadioButtonList rblItem;
        private Button btnConfirm;

        protected override void InitializeSkin(Control skin)
        {
            tbxTitle = (TextBox)skin.FindControl("tbxTitle");
            tbxEmail = (TextBox)skin.FindControl("tbxEmail");
            tbxPhone = (TextBox)skin.FindControl("tbxPhone");
            tbxBody = (TextBox)skin.FindControl("tbxBody");
            tbxLinkMan = (TextBox)skin.FindControl("tbxLinkMan");
            tbxFax = (TextBox)skin.FindControl("tbxFax");
            tbxMobile = (TextBox)skin.FindControl("tbxMobile");
            tbxAddress = (TextBox)skin.FindControl("tbxAddress");
            rblItem = (GuestBookItemRadioButtonList)skin.FindControl("rblItem");
            rblSex = (SexRadio)skin.FindControl("rblSex");           

            btnConfirm = (Button)skin.FindControl("btnConfirm");

            btnConfirm.Click += new EventHandler(btnConfirm_Click);

            if (SiteContext.Current.Context.User.Identity.IsAuthenticated)
            {
                tbxLinkMan.Text = SiteContext.Current.User.Profile.Name;
                tbxEmail.Text = SiteContext.Current.User.LoginName;
            }
        }

        void btnConfirm_Click(object sender, EventArgs e)
        {
            GuestbookInfo info = new GuestbookInfo();
            info.Content = tbxBody.Text.Trim();
            info.Email = tbxEmail.Text.Trim();
            info.Fax = tbxFax.Text.Trim();
            info.IsRead = false;
            info.LinkMan = tbxLinkMan.Text.Trim();
            info.Mobile = tbxMobile.Text.Trim();
            info.Tel = tbxPhone.Text.Trim();
            info.Title = tbxTitle.Text.Trim();
            info.ItemType = rblItem.SelectedValue;
            info.Address = tbxAddress.Text.Trim();
            info.Sex = rblSex.SelectedValue;

            GuestBook.Insert(info);
        }



        protected override string DefaultSkinFilename
        {
            get { return "GuestBook/GuestBookAdd.ascx"; }
        }
    }
}
